<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="icon" href="/public/img/favicon.ico">
    <link rel="stylesheet" href="/public/css/login.css">
</head>

<body>
    <div class="login-container">
        <div class="left-container">
            <div class="title"><span>登陆</span></div>
            <div class="input-container">
                <input type="text" name="username" id="username" placeholder="用户名">
                <input type="password" name="password" id="password" placeholder="密码">
            </div>
            <!-- <div class="message-container">
                <span>忘记密码</span>
            </div> -->
        </div>
        <div class="right-container">
            <div class="regist-container">
                <span class="regist">注册</span>
            </div>
            <div class="action-container" id="action-container">
                <span>提交</span>
            </div>
        </div>
    </div>

    <script src="/node_modules/jquery/dist/jquery.js"></script>
    <script>

        // $('.regist').click(() => {
        //     var username = $('#username').val();
        //     var password = $('#password').val();
        //     $.ajax({
        //         url: '/regist',
        //         dataType: 'json',
        //         type: 'post',
        //         data: 'username=' + username + '&password=' + password,
        //         success: function (data) {
        //             console.log(data);
        //         },
        //         error: function () {
        //             console.log("错误");
        //         }
        //     })
        // })

        $('.action-container').click(() => {
            var username = $('#username').val();
            var password = $('#password').val();
            $.ajax({
                url: '/login',
                dataType: 'json',
                type: 'post',
                data: 'username=' + username + '&password=' + password,
                success: function (data) {
                    console.log(data);
                    var err_code = data.err_code;
                    console.log(data)
                    if (err_code === 0) {
                        window.location.href = '/admin';
                    } else if (err_code === 1) {
                        window.alert(data.message);
                    } else if (err_code === 500) {
                        window.alert(data.message);
                    }
                },
                error: function () {
                    console.log("错误");
                }
            })
        })
    </script>

</html>